//
//  BTELoginView.swift
//  BTE
//
//  Created by Mike Zhang on 2025/8/14.
//

import UIKit
import SnapKit

class BTELoginView: UIView {
    
    var clicke:(()->())?
    
    var countdownTimer: Timer?
    
    var remainingSeconds = 60
    
    let totalCountdownSeconds = 60
    
    private let bgimage = UIImageView.init(image: UIImage.init(named: "Mask group1111111"))
    
    private let topimage = UIImageView.init(image: UIImage.init(named: "Group 1171276345"))
    
    private let mainimage = UIImageView.init(image: UIImage.init(named: "Group eeee1171276730"))
    
    private let t1 = UILabel()
    
     let t1textfeild = UITextField()
    
    private let t1box = UIView.init()
    
    private let t2 = UILabel()
    
    private let t2box = UIView.init()
    
     let t2textfield = UITextField()
    
    let t2getcodebutton = UIButton.init(title: BTELanguageManager.shared.localizedString(forKey: "Get Code"),font: .systemFont(ofSize: 14,weight: .bold),titleColor: .colorWithHex("#187CA5")!)
    
    let button = UIButton.init(title: BTELanguageManager.shared.localizedString(forKey: "Voice verifcation?"),font: .systemFont(ofSize: 12),titleColor: .colorWithHex("#187CA5")!,image: UIImage.init(named: "Frame"))
    
    private let buttomBox = UIView.init(backgroundColor: .clear)
    
    let loginButton = UIImageView.init(image: UIImage.init(named: "Rectangle xxxxxx95"))
    
    private let loginBut = UILabel.init()
    
    let privicyView = PrivacyAgreementView()
    
    
    let bac = UIButton.init(title: "", image: UIImage.init(named: "fewfewfwefwefew"))
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .white
        
        t1textfeild.keyboardType = .numberPad
        
        mainimage.isUserInteractionEnabled = true
        
        bgimage.contentMode = .scaleAspectFit
        addSubview(bgimage)
        bgimage.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        addSubview(topimage)
        topimage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(100)
        }
        
        addSubview(mainimage)
        mainimage.snp.makeConstraints { make in
            make.top.equalTo(topimage.snp.bottom).offset(30)
            make.left.right.equalToSuperview().inset(23)
            make.height.equalTo(((UIScreen.main.bounds.width-23-23) * mainimage.frame.height) / mainimage.frame.width)
        }
        
        t1.text = BTELanguageManager.shared.localizedString(forKey: "Mobile number")
        t1.textColor = .black
        t1.font = UIFont.systemFont(ofSize: 16, weight: .bold)
        mainimage.addSubview(t1)
        t1.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(14)
            make.top.equalToSuperview().offset(33)
        }
        
        t1box.backgroundColor = .colorWithHex("#C4F9FF", alpha: 1.0)
        
        t1textfeild.font = .systemFont(ofSize: 14)
        t1textfeild.placeholder = BTELanguageManager.shared.localizedString(forKey: "Enter mobile number")
        t1textfeild.textColor = .black
        t1box.addSubview(t1textfeild)
        t1textfeild.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.right.equalToSuperview().inset(18)
        }
        
        
        mainimage.addSubview(t1box)
        t1box.backgroundColor = .colorWithHex("#C4F9FF")
        t1box.roundCorners(.allCorners, radius: 12)
        t1box.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(14)
            make.top.equalTo(t1.snp.bottom).offset(10)
            make.height.equalTo(53)
        }
        
        
        t2.text = BTELanguageManager.shared.localizedString(forKey: "Verification code")
        t2.textColor = .black
        t2.font = UIFont.systemFont(ofSize: 16, weight: .bold)
        mainimage.addSubview(t2)
        t2.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(14)
            make.top.equalTo(t1box.snp.bottom).offset(18)
        }
        
        t2box.backgroundColor = .colorWithHex("#C4F9FF", alpha: 1.0)
        
        mainimage.addSubview(t2box)
        t2box.backgroundColor = .colorWithHex("#C4F9FF")
        t2box.roundCorners(.allCorners, radius: 12)
        t2box.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(14)
            make.top.equalTo(t2.snp.bottom).offset(10)
            make.height.equalTo(53)
        }
        
        t2box.addSubview(t2getcodebutton)
        t2getcodebutton.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(18)
            make.centerY.equalToSuperview()
            make.width.equalTo(110)
        }
        
        t2box.addSubview(t2textfield)
        t2textfield.font = .systemFont(ofSize: 14)
        t2textfield.placeholder = BTELanguageManager.shared.localizedString(forKey: "Verification code")
        t2textfield.textColor = .black
        t2textfield.keyboardType = .numberPad
        t2textfield.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(18)
            make.top.bottom.equalToSuperview()
            make.right.equalTo(t2getcodebutton.snp.left).offset(-20)
        }
        
        mainimage.addSubview(button)
       
        button.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(t2box.snp.bottom).offset(18)
        }
        
        mainimage.addSubview(buttomBox)
        buttomBox.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(18)
            make.bottom.equalToSuperview().offset(-60)
        }
        
        
        buttomBox.addSubview(loginButton)
        loginButton.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(47)
            make.top.equalToSuperview()
        }
        
        loginBut.text = BTELanguageManager.shared.localizedString(forKey: "Login")
        loginBut.textColor = .colorWithHex("#ffffff")
        loginBut.font = .systemFont(ofSize: 16,weight: .bold)
        loginButton.addSubview(loginBut)
        loginBut.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
        
        privicyView.configure(withText: BTELanguageManager.shared.localizedString(forKey: "I have read and agree"), linkText: BTELanguageManager.shared.localizedString(forKey: "<Privacy Agreement>"), fontSize: 14)
        buttomBox.addSubview(privicyView)
        privicyView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.centerX.equalToSuperview()
            make.top.equalTo(loginBut.snp.bottom).offset(28)
        }
        
        addSubview(bac)
        bac.snp.makeConstraints { make in
            make.width.height.equalTo(30)
            make.left.equalToSuperview().offset(20)
            make.top.equalToSuperview().offset(57)
        }
        bac.addTarget(self, action: #selector(few), for: .touchUpInside)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func few(){
        clicke?()
    }
    
}
